<template>
	<view :style="viewColor">
	
		<!-- 自定义顶部背景颜色 -->
		<view class='integral-details' >
			<view class='header'>
			
			</view>
			<view class='wrapper'>
				<!-- <view class='nav acea-row'>
					<view class='item acea-row row-center-wrapper' :class='current==index?"on":""' v-for="(item,index) in navList" :key='index'
					 @click='nav(index,item.id)'></text>{{item.name}}</view>
				</view> -->
				<view class='list'  >
					<view class='tip' v-if="userInfo.clear && userInfo.clear.status && userInfo.clear.nextClearIntegral > 0"><text class='iconfont icon-shuoming'></text>
						<text class="tip-text">提示：您有部分积分将于{{userInfo.clear.nextClearDay}}过期，请尽快使用！</text>
					</view>
					<view class='item acea-row row-between-wrapper' v-for="(item,index) in integralList" :key="index">
						<view class="itemLis">
							<view>店铺名称：<em>{{item.mer_name}}</em></view>							
						</view>
						<view class="itemLis">
							     <view>上月流水：<span>{{item.liushui1}}</span></view>
								<view>上月让利：<span>{{item.rangli_price1}}</span></view>														
						</view>
						<view class="itemLis">
						    <view>本月流水：<span>{{item.liushui2}}</span></view>
							<view>本月让利：<span>{{item.rangli_price2}}</span></view>							
						</view>
						<view class="itemLis">
							<view>总流水：<span>{{item.liushui}}</span></view>
							<view>总让利：<span>{{item.rangli_price}}</span></view>						
						</view>						
						<view class="itemLis">							
							<view>地址：<span>{{item.name}}</span></view>							
						</view>
						
					</view>
					<view class='loadingicon acea-row row-center-wrapper' v-if="integralList.length>0">
						<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
					</view>
					<view v-if="integralList.length == 0">
						<emptyPage title="暂无积分记录哦～" :noImage="`${domain}/static/images/noRecord.png`"></emptyPage>
					</view>
				</view>
				
			</view>
		</view>
		<view class="instructions" v-if="showProtocol">
			<view class="agreement-count">
				<view class="setAgCount">
					<view class="title">积分说明</view>
					<view class="agBox">
						<view class="content">
							<jyf-parser :html="protocol" ref="article" :tag-style="tagStyle"></jyf-parser>
						</view>
					</view>
				</view>
				<text class="icon iconfont icon-ic_close1" @click="showProtocol = false"></text>
			</view>
		</view>
	</view>
</template>

<script>
	// +----------------------------------------------------------------------
	// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
	// +----------------------------------------------------------------------
	// | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
	// +----------------------------------------------------------------------
	// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
	// +----------------------------------------------------------------------
	// | Author: CRMEB Team <admin@crmeb.com>
	// +----------------------------------------------------------------------
	let sysHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
	import { getIntegralInfo, getIntegralList, getAgreementApi,orderHuifulist ,shengshiqulist} from '@/api/user.js';
	import { mapGetters } from "vuex";
	import emptyPage from '@/components/emptyPage.vue';
	import parser from "@/components/jyf-parser/jyf-parser";
	import { toLogin } from '@/libs/login.js';
	import { HTTP_REQUEST_URL } from '@/config/app';
	const app = getApp();
	export default {
		components: {
			emptyPage,
			"jyf-parser": parser,
		},
		data() {
			return {
				sysHeight: sysHeight,
				//#ifdef H5
				marTop: 0,
				//#endif
				//#ifdef MP
				marTop: uni.getSystemInfoSync().statusBarHeight+43+'px',
				//#endif
				//#ifdef APP-PLUS
				marTop: uni.getSystemInfoSync().statusBarHeight+'px',
				//#endif
				domain: HTTP_REQUEST_URL,
				navList: [{
							'name': '未支付',
							'id': '0'
						},
						{
							'name': '已支付',
							'id': '1'
						}
					],
			/* 	navList: [{
						'name': '分值明细',
						'icon': 'icon-ic_list'
					},
					{
						'name': '分值提升',
						'icon': 'icon-a-icon_Scoreincrease'
					}
				], */
				current: 0,
				page: 1,
				limit: 10,
				type:'1',
				integralList: [],
				userInfo:{},
				loadend: false,
				loading: false,
				loadTitle: '加载更多',
				showProtocol: false,
				protocol: '',
				tagStyle: {
					img: 'width:100%;display:block;',
					video: 'width:100%;'
				},
				integral_status: true,
			};
		},
		computed: mapGetters(['isLogin','viewColor']),
		onLoad() {
			// if (this.isLogin) {
			// 	this.getUserInfo();
			// } else {
			// 	toLogin()
			// }
			//this.getAgreement();
			this.getIntegralList();
		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function () {
			this.getIntegralList();
		},
		methods: {
			/**
			 * 表格时间格式化
			 */
			 formatDate(cellValue) {
			  if (cellValue == null || cellValue == "") return "";
			  var date = new Date(cellValue) 
			  var year = date.getFullYear()
			  var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
			  var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate() 
			  var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours() 
			  var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes() 
			  var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
			  return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
			},
			goBack: function() {
				uni.navigateBack();
			},
			getUserInfo: function() {
				let that = this;
				getIntegralInfo().then(function(res) {
					that.$set(that,'userInfo',res.data);
					that.getIntegralList()
				}).catch(res => {
					this.integral_status = false
					return that.$util.Tips({
						title: res
					}, {
						tab: 3,
						url: 1
					});
				});
			},
			/*获取积分说明*/
			getAgreement() {
				let that = this
				getAgreementApi('sys_integral_rule').then(res => {
					that.protocol = res.data.sys_integral_rule
				})
			},
			/**
			 * 获取积分明细
			 */
			getIntegralList: function() {
				let that = this;
				//if (that.loading) return;
				//if (that.loadend) return;
				that.loading = true;
				that.loadTitle = '';
				shengshiqulist({
					type: that.type,
					page: that.page,
					limit: that.limit
				}).then(function(res) {
					let list = res.data.list,
					loadend = list.length < that.limit;
					that.integralList = that.$util.SplitArray(list, that.integralList);
					that.$set(that,'integralList',that.integralList);
					that.page = that.page + 1;
					that.loading = false;
					that.loadend = loadend;
					that.loadTitle = loadend ? '哼~😕我也是有底线的~' : "加载更多";
				}, function(res) {
					that.loading = false;
					that.loadTitle = '加载更多';
				});
			},
			shareIntegral(){
				uni.setStorageSync('isIntegral',true)
				uni.switchTab({
					url: '/pages/index/index'
				});
			},
			nav: function(current,type) {				
				this.current = current;
				this.type = type
				this.page =1
				this.limit =10
				this.integralList =[]
				this.getIntegralList()
			}
		}
	}
</script>

<style scoped lang="scss">
	.sys-title .iconfont{ position: absolute; left: 30rpx; }
	.sys-head .bg { background-color: var(--view-theme); }
	.integral-details .header {
		background-image: url('');
		background-color: var(--view-theme);
		background-repeat: no-repeat;
		width: 100%;
		height: 200rpx;
		font-size: 72rpx;
		color: #fff;
		padding: 31rpx 0 45rpx 0;
		box-sizing: border-box;
		text-align: center;
		background-size: 100% auto;
		background-position: left bottom;
	}
	.integral-details .header .currentScore {
		font-size: 26rpx;
		color: rgba(255, 255, 255, 0.8);
		text-align: center;
		margin-bottom: 11rpx;
	}
	.currentScore .iconfont{
		display: inline-block;
		margin-left: 8rpx;
		font-size: 28rpx;
	}
	.integral-details .header .line {
		width: 60rpx;
		height: 3rpx;
		background-color: #fff;
		margin: 20rpx auto 0 auto;
	}
	.integral-details .header .nav {
		font-size: 22rpx;
		color: rgba(255, 255, 255, 0.8);
		flex: 1;
		margin-top: 35rpx;
	}
	.integral-details .header .nav .item {
		width: 50%;
		text-align: center;
	}
	.integral-details .header .nav .item .num {
		color: #fff;
		font-size: 40rpx;
		margin-bottom: 5rpx;
	}
	.integral-details .wrapper .nav {
		flex: 1;
		width: 690rpx;
		border-radius: 24rpx 24rpx 0 0;
		margin: -96rpx auto 0 auto;
		background-color: #f7f7f7;
		height: 96rpx;
		font-size: 30rpx;
		color: #bbb;
	}
	.integral-details .wrapper .nav .item {
		text-align: center;
		width: 50%;
	}
	.integral-details .wrapper .nav .item.on {
		background-color: #fff;
		color: var(--view-theme);
		font-weight: bold;
		border-radius: 24rpx 0 0 0;
		.iconfont {
			font-weight: normal;
		}
	}
	.p-color {
		color: var(--view-priceColor);
	}
	.item-label{
		font-size: 18rpx;
		display: flex;
		width: 76rpx;
		height: 26rpx;
		text-align: center;
		justify-content: center;
		background-color: var(--view-bgColor);
		margin-right: 6rpx;
		font-weight: normal;
	}
	.integral-details .item .orange-text {
		color: #FF7F00;
		margin-top: 4rpx;
	}
	.integral-details .wrapper .nav .item:nth-of-type(3).on {
		border-radius: 0 20rpx 0 0;
	}
	.integral-details .wrapper .nav .item .iconfont {
		font-size: 38rpx;
		margin-right: 10rpx;
	}
	.integral-details .wrapper .list {
		background-color: #fff;
		padding: 24rpx 30rpx;
		min-height: calc(100vh - 460rpx);
	}
	.integral-details .wrapper .list .tip {
		font-size: 25rpx;
		width: 690rpx;
		border-radius: 50rpx;
		background-color: #fff5e2;
		border: 1px solid #ffeac1;
		color: #c8a86b;
		padding: 10rpx 20rpx 10rpx 55rpx;
		box-sizing: border-box;
		margin-bottom: 24rpx;
		position: relative;
	}
	.integral-details .wrapper .list .tip .iconfont {
		font-size: 35rpx;
		margin-right: 15rpx;
		position: absolute;
		top: 10rpx;
		left: 16rpx;
	}
	.integral-details .wrapper .list .item {
		padding: 24rpx 0;
		border-bottom: 1rpx solid #eee;
		font-size: 24rpx;
		color: #999;
	}
	.integral-details .wrapper .list .item .itemLis{
	       display: flex;
		   justify-content: space-between;
		   align-items: center;
		   padding-bottom: 20rpx;
		   width: 100%;
		   em{
			   font-style: normal;
		   }
		   span{
			   color: #282828;
		   }
		   view{
			   em{
				   color: #FF7F00;
			   }
		   }
	}
	.integral-details .wrapper .list .item .state {
		font-size: 28rpx;
		color: #282828;
		margin-bottom: 18rpx;
		max-width: 400rpx;
	}
	.integral-details .wrapper .list .item .num {
		font-size: 36rpx;
		color: #16AC57;
		&.p-color{
			color: var(--view-priceColor);
		}
	}
	.integral-details .wrapper .list2 {
		background-color: #fff;
		padding: 24rpx 0;
	}
	.integral-details .wrapper .list2 .item {
		background-image: linear-gradient(to right, #fff7e7 0%, #fffdf9 100%);
		width: 690rpx;
		height: 180rpx;
		position: relative;
		border-radius: 24rpx;
		margin: 0 auto 20rpx auto;
		padding: 0 25rpx 0 180rpx;
		box-sizing: border-box;
	}
	.integral-details .wrapper .list2 .item .pictrue {
		width: 90rpx;
		height: 150rpx;
		position: absolute;
		bottom: 0;
		left: 45rpx;
	}
	.integral-details .wrapper .list2 .item .pictrue image {
		width: 100%;
		height: 100%;
	}
	.integral-details .wrapper .list2 .item .name {
		width: 285rpx;
		font-size: 30rpx;
		font-weight: bold;
		color: #c8a86b;
	}
	.integral-details .wrapper .list2 .item .earn {
		font-size: 24rpx;
		color: #c8a86b;
		border: 2rpx solid #c8a86b;
		display: flex;
		align-items: center;
		justify-content: center;
		height: 56rpx;
		width: 120rpx;
		border-radius: 50rpx;
	}
	
</style>
